package com.ruoyi.basedata.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import lombok.*;
import com.ruoyi.common.annotation.Excel;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 用量区间设置对象 t_usage_range
 *
 * @author TsingYu
 * @date 2024-07-13
 */
@TableName("t_usage_range")
@Data
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UsageRange implements Serializable {

    private static final long serialVersionUID = 8719592189734396857L;
    /**
     * 大表
     */
    public static final String WARN_TARGET_TYPE_DB = "1";
    /**
     * 小表
     */
    public static final String WARN_TARGET_TYPE_XB = "2";
    /**
     * 通用设置客户id和通用策略值
     */
    public static final String COMMON_FLAG = "0";
    /**
     * 通用设置策略名称
     */
    public static final String COMMON_STRATEGY_NAME = "通用";
    @Data
    @ToString
    @AllArgsConstructor
    @NoArgsConstructor
    public static class UsageRangeData implements Serializable{

        private static final long serialVersionUID = -4427644813352814210L;

        /**
         * 报警类型，字典类型：warn_param_type
         */
        @NotBlank(message = "报警类型不能为空")
        private String warnType;

        /**
         * 报警值
         */
        @NotNull(message = "报警值不能为空")
        private BigDecimal value;

        /**
         * 是否启用预警，0：否、1：是
         */
        @NotNull(message = "是否启用预警不能为空")
        private Boolean enabled;
    }

    /**
     * 客户id，通用设置客户id为0
     */
    @TableField("tenant_id")
    @NotBlank(message = "客户id不能为空")
    private String tenantId;

    /**
     * 报警对象，字典类型：warn_target_type
     */
    @TableField("warn_target_type")
    @NotBlank(message = "报警对象不能为空")
    private String warnTargetType;

    /**
     * 策略
     */
    @TableField("strategy")
    private String strategy;

    /**
     * 策略
     */
    @Excel(name = "策略名称")
    @TableField("strategy_name")
    @NotBlank(message = "策略名称不能为空")
    private String strategyName;

    /**
     * 夜间小流开始时间
     */
    @JsonSerialize(using = LocalTimeSerializer.class)
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    @JsonFormat(pattern = "HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "夜间小流开始时间", width = 30, dateFormat = "HH:mm:ss")
    @TableField("night_flow_begin_time")
    private LocalTime nightFlowBeginTime;

    /**
     * 夜间小流结束时间
     */
    @JsonSerialize(using = LocalTimeSerializer.class)
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    @JsonFormat(pattern = "HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "夜间小流结束时间", width = 30, dateFormat = "HH:mm:ss")
    @TableField("night_flow_end_time")
    private LocalTime nightFlowEndTime;

    /**
     * 报警类型，字典类型：warn_param_type
     */
    @TableField("warn_type")
    @JsonIgnore
    private String warnType;

    /**
     * 报警值
     */
    @Excel(name = "报警值")
    @TableField("value")
    @JsonIgnore
    private BigDecimal value;

    /**
     * 是否启用预警，0：否、1：是
     */
    @Excel(name = "是否启用预警", readConverterExp = "0=否,1=是")
    @TableField("enabled")
    @JsonIgnore
    private Boolean enabled;

    /**
     * 创建者
     */
    @TableField("create_by")
    private String createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;

    /**
     * 更新者
     */
    @TableField("update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("update_time")
    private Date updateTime;

    @TableField(exist = false)
    @NotEmpty(message = "报警数据不能为空")
    private List<UsageRangeData> data;
}
